package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabDiagnosTempDesc;
import com.ysd.lis.mapper.lab.LabDiagnosTempDescMapper;
import com.ysd.lis.request.lab.DiagnosTempDto;
import com.ysd.lis.service.lab.LabDiagnosTempDescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 通道号管理表 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-10-29
 */
@Service
public class LabDiagnosTempDescServiceImpl extends ServiceImpl<LabDiagnosTempDescMapper, LabDiagnosTempDesc> implements LabDiagnosTempDescService {
    @Autowired
    LabDiagnosTempDescMapper labDiagnosTempDescMapper;
    @Override
    public Result findDiagnosTempDescList(DiagnosTempDto param) {
        MPJLambdaWrapper<LabDiagnosTempDesc> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LabDiagnosTempDesc.class);
        if (StringUtils.isNotBlank(param.getDiagnosTempId())) {
            queryWrapper.eq(LabDiagnosTempDesc::getDiagnosTempId,param.getDiagnosTempId());
        }

        queryWrapper.eq(LabDiagnosTempDesc::getDelFlag, 0)
                .orderByAsc(LabDiagnosTempDesc::getSeq);
        return Result.succ(1, "查询成功", labDiagnosTempDescMapper.selectList(queryWrapper));
    }

    @Override
    public Result batchDeleteDiagnosTempDesc(DiagnosTempDto dto) {
        List<LabDiagnosTempDesc> diagnosTempDescList = dto.getDiagnosTempDescList();
        List<String> ids = diagnosTempDescList.stream().map(LabDiagnosTempDesc::getId).collect(Collectors.toList());

        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }

    @Override
    public Result addDiagnosTempDesc(LabDiagnosTempDesc project) {
        int insert = labDiagnosTempDescMapper.insert(project);
        if(insert>0){
            return Result.succ(1, "添加成功", project);
        }else {
            return Result.succ(400, "添加失败", "");
        }
    }

    @Override
    public Result editDiagnosTempDesc(LabDiagnosTempDesc project) {
        int updateById = labDiagnosTempDescMapper.updateById(project);
        if(updateById>0){
            return Result.succ(1, "修改成功", project);
        }else {
            return Result.succ(400, "修改失败", "");
        }
    }
}
